import { tool } from '@langchain/core/tools';
import { cloneDeep } from 'lodash-es';
import { z } from 'zod';

const schema = z.object({
  name: z.string().describe('hmi 3D场景图纸名称'),
});

type Schema = z.infer<typeof schema>;

export const createSceneTool = () => {
  const ragTool = tool(
    ({ name }: Schema) => {
      console.log('场景创建工具调用');

      const scene = cloneDeep(DEFAULRT_SCENE);

      scene.scene.name = name || '新建场景';

      console.log('成功创建了场景', scene);

      return scene;
    },
    {
      name: 'HMI 3D场景图纸创建工具',
      description: '创建hmi 3D 场景图纸',
      schema,
    },
  );

  return ragTool;
};

export const DEFAULRT_SCENE = {
  scene: {
    id: 0,
    name: '新建场景',
    type: 'Scene',
    visible: true,
    selectable: true,
    transformable: true,
    deleteable: false,
    copiable: false,
    moveable: true,
    position: [0, 0, 0],
    rotation: [0, 0, 0],
    scale: [1, 1, 1],
    components: [],
    index: 4,
    code: '',
    desc: '',
    ver: '1.0.0',
    company: '',
    author: '',
    date: '',
    refreshCycle: 1000,
    debug: false,
    backgroundColor: 'rgb(53, 53, 53)',
    backgroundTexture: '',
    backgroundBlurriness: 0,
    backgroundIntensity: 1,
    backgroundRotation: 0,
    environmentTexture: '',
    environmentIntensity: 1,
    environmentRotation: 0,
    fogEnable: false,
    fogColor: '#000000',
    fogNear: 10,
    fogFar: 100,
    gridEnable: true,
    gridSize: 50,
    gridColor1: '#444444',
    gridColor2: '#888888',
    children: [
      {
        parent: 0,
        id: 1,
        name: '环境光',
        type: 'AmbientLight',
        visible: true,
        selectable: true,
        transformable: true,
        deleteable: true,
        copiable: true,
        moveable: true,
        position: [0, 0, 0],
        rotation: [0, 0, 0],
        scale: [1, 1, 1],
        children: [],
        components: [],
        color: '#ffffff',
        intensity: 1,
      },
      {
        parent: 0,
        id: 2,
        name: '平行光',
        type: 'DirectionalLight',
        visible: true,
        selectable: true,
        transformable: true,
        deleteable: true,
        copiable: true,
        moveable: true,
        position: [4, 6, 3],
        rotation: [0, 0, 0],
        scale: [1, 1, 1],
        children: [],
        components: [],
        color: '#ffffff',
        intensity: 3,
      },
      {
        parent: 0,
        id: 3,
        name: '透视相机',
        type: 'PerspectiveCamera',
        visible: true,
        selectable: true,
        transformable: true,
        deleteable: true,
        copiable: true,
        moveable: true,
        position: [0, 15, 30],
        rotation: [-26.6, 0, 0],
        scale: [1, 1, 1],
        children: [],
        components: [{ id: 1, type: 'OrbitControls', name: '轨道控制' }],
        fov: 45,
        near: 0.1,
        far: 2000,
      },
    ],
  },
  materials: [],
};
